package com.ofo.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.ofo.dao.MarksDao;
import com.ofo.model.Marks;

@Repository("marksDao")
public class MarksDaoImpl implements MarksDao {
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public boolean addMarks(Marks marks) {
		String sql = "INSERT INTO marks (`marks`, `createUser`) VALUES(?,?)";
		return jdbcTemplate.update(sql, marks.getMarks(), marks.getCreateUser()) > 0;
	}

	@Override
	public Marks getMarks(Integer marks) {
		String sql = "SELECT * FROM marks where marks=?";
		try {
			return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<Marks>(Marks.class), marks);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public List<Marks> getMarkss() {
		try {
			String sql = "SELECT * FROM marks";
			return jdbcTemplate.query(sql, new BeanPropertyRowMapper<Marks>(Marks.class));
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public void deleteMarks(Integer id) {
		String sql = "DELETE FROM marks where id=?";
		jdbcTemplate.update(sql, id);
	}

}
